package com.aaa.service.mht.impl;

import com.aaa.dao.mht.ViewTestResultDao;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.mht.ViewTestResultmht;
import com.aaa.service.mht.ViewTestResultService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("viewTestResultService")
public class ViewTestResultServiceImpl implements ViewTestResultService {
    @Resource
    ViewTestResultDao viewTestResultDao;

    @Override
    public List<ViewTestResultmht> queryAllByCondition(PageSortEntity pageSortEntity, ViewTestResultmht viewTestResultmht) {
        PageHelper.startPage(pageSortEntity.getPage(), pageSortEntity.getLimit());
        List<ViewTestResultmht> viewTestResultMhtList = viewTestResultDao.queryAllByCondition(viewTestResultmht);
        Page page = (Page) viewTestResultMhtList;
        return page;
    }

    @Override
    public Map<String, Integer> queryResultAll() {
            int a1=0;
            int a2=0;
            int a3=0;
            int a4=0;
            int a5=0;
            int a6=0;
            int a7=0;
            int a8=0;
            int a9=0;
            int zf=0;
            List<ViewTestResultmht> viewMhts = viewTestResultDao.queryAll();
            for (ViewTestResultmht viewMht : viewMhts) {
                int  f1 = viewMht.getXx();
                int  f2 = viewMht.getDr();
                int  f3 = viewMht.getGd();
                int  f4 = viewMht.getZz();
                int  f5 = viewMht.getGm();
                int  f6 = viewMht.getSt();
                int  f7 = viewMht.getKb();
                int  f8 = viewMht.getCd();
                int  f9 = viewMht.getXdpg();
                int  f10 = viewMht.getZf();
                if(f1>=8){
                    a1++;
                }
                if(f2>=8){
                    a2++;
                }
                if(f3>=8){
                    a3++;
                }
                if(f4>=8){
                    a4++;
                }
                if(f5>=8){
                    a5++;
                }
                if(f6>=8){
                    a6++;
                }
                if(f7>=8){
                    a7++;
                }
                if(f8>=8){
                    a8++;
                }
                if(f9>=8){
                    a9++;
                }
                if(f10!=0){
                    zf++;
                }
            }
            Map<String, Integer> map = new HashMap<>();
            map.put("a1", a1);
            map.put("a2", a2);
            map.put("a3", a3);
            map.put("a4", a4);
            map.put("a5", a5);
            map.put("a6", a6);
            map.put("a7", a7);
            map.put("a8", a8);
            map.put("a9", a9);
            map.put("zf",zf);
            return map;
        }

    @Override
    public ViewTestResultmht queryAll(ViewTestResultmht viewTestResultmht) {
        return  viewTestResultDao.queryById(viewTestResultmht);
    }



    @Override
    public boolean deleteById(Integer id) {
        return this.viewTestResultDao.deleteById(id) > 0;
    }

    @Override
    public Integer delTestPlanBatch(int[] id) {
        return viewTestResultDao.delALLById(id);
    }
}
